package com.cmb.homework0722;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
/**
 * @Author llk
 * @Description //用户类
 * @Date 21:36 2022/7/23
 **/
public class Customer {
    // 用户ID
    private Integer id;
    // 用户名称
    private String name;
    // 用户拥有的积分
    private BigDecimal credit;
    // 用户购买的商品集合
    private HashMap<String, Integer> goodsMap;

    public Customer(Integer id, String name, BigDecimal credit, HashMap<String, Integer> goodsMap) {
        this.id = id;
        this.name = name;
        this.credit = credit;
        this.goodsMap = goodsMap;
    }

    public Customer(String name, BigDecimal credit) {
        this.id = id;
        this.name = name;
        this.credit = credit;
    }

    public BigDecimal getCredit() {
        return credit;
    }

    public void setCredit(BigDecimal credit) {
        this.credit = credit;
    }

    public HashMap<String, Integer> getGoodsMap() {
        return goodsMap;
    }

    public Integer getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    /**
     * @return java.lang.Integer
     * @Author llk
     * @Description // 获取用户购买的商品个数
     * @Date 21:29 2022/7/23
     * @Param []
     **/
    public Integer getMapValueSum() {
        int sum = 0;
        for (Integer ele :
                this.getGoodsMap().values()) {
            sum += ele;
        }
        return sum;
    }
}
